#include <iostream>
#include <vector>
using namespace std;
//#include "reopen.h"

int n,temp,total=0;
int d[100005];

int main(void){
//	reopen("5019_t");
	cin>>n;
	for(int i=0;i<n;i++){
//		cout<<temp;
		cin>>d[i];
//		cout<<temp<<" ";
	}

	for(int l=0;l<n;){
		if(d[l]==0){
			l++;
			continue;
		}
		for(int r=l;r<n;r++){
			if(d[r]==0)break;
			d[r]--;
		}
		total++;
	}
	cout<<total;
	return 0;
}